<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class OrderDelay implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $order;
    public function __construct(Order $order,$delay)
    {
        $this->order = $order;
        $this->delay = $delay;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if($this->order->paid_at){
            return;
        }
        \DB::transaction(function(){
            $this->order->update(['closed'=>true]);

            foreach ($this->order->items as $item) {
                // $this->order->setInc(['amout'=>$item->amout]);   
                $item->productSku->addStock($item->amount);
            }

        })
    }

}
